﻿using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using BySoft.Server.Business;
using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Enum;
using BySoft.Web.Utility;
using BySoft.Server.Consts;
using BySoft.Server.Common;
using BySoft.Web.Controls;

namespace TaiChySystem.Web.Site.ComPage
{
    public partial class ViewPicDetial : BasePage
    {
        private DataTable CreateDT()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("AttachmentID");//0
            dt.Columns.Add("FileType");//0
            dt.Columns.Add("FileSize");//0
            dt.Columns.Add("UpDate");
            dt.Columns.Add("FileURL");
            dt.Columns.Add("FileName");
            dt.Columns.Add("FormType");
            dt.Columns.Add("Status");
            dt.Columns.Add("FormID");
            return dt;
        }

        protected DataTable DtViewPicDetial
        {
            get
            {
                if (Session["DtViewPicDetial"] != null)
                {
                    return (DataTable)Session["DtViewPicDetial"];
                }
                else
                {
                    return CreateDT();
                }
            }
            set
            {
                Session["DtViewPicDetial"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string strid = UIHelper.GetQueryStringValue("id").Trim();
                if (!string.IsNullOrEmpty(strid) && strid.Trim() != "")
                {
                    DataTable dtPic = MdParts.SelectPic(strid);
                    DataTable dtTemp = DtViewPicDetial.Clone();
                    if (dtPic != null && dtPic.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtPic.Rows)
                        {
                            DataRow drnew = dtTemp.NewRow();
                            drnew["AttachmentID"] = dr["AttachmentID"];
                            drnew["FileType"] = dr["FileType"];
                            drnew["FileSize"] = dr["FileSize"];
                            drnew["UpDate"] = dr["UpDateTime"];
                            drnew["FileURL"] = dr["FileURL"];
                            drnew["FileName"] = dr["FileName"];
                            drnew["FormID"] = dr["FormID"];
                            drnew["FormType"] = dr["FormType"];
                            drnew["Status"] = dr["Status"];
                            dtTemp.Rows.Add(drnew);
                        }
                    }
                    DtViewPicDetial = dtTemp.Copy();
                }
                BindData();
            }
        }

        private void BindData()
        {
            DataTable dttemp = DtViewPicDetial.Copy();

            if (DtViewPicDetial.Rows.Count > 0)
            {
                dttemp.Columns.Add("ShowPic", typeof(string));
                foreach (DataRow row in dttemp.Rows)
                {
                    row["ShowPic"] = "..\\Files\\UpLoadImage\\" + CommonMethod.GetString(row["FileURL"]);
                }
                dlShoppingCart.DataSource = dttemp;
                dlShoppingCart.DataBind();
            }
            else
            {
                dlShoppingCart.DataSource = null;
                dlShoppingCart.DataBind();
            }

            //UIHelper.RunScript(this.UpdatePanel1, "iframeAutoFit();");
        }
    }
}